﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="ProductManagement.aspx.cs" Inherits="XYZ_Inventory.ProductManagement"
Culture="si-LK" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="Styles/GridView.css" rel="stylesheet" type="text/css"/>
    <link href="Styles/SearchBox.css" rel="stylesheet" type="text/css"/>
    <link href="Styles/DetailsView.css" rel="stylesheet" type="text/css"/>
    <link href="Styles/CustomTable.css" rel="stylesheet" type="text/css"/>
    <link href="Styles/ValidationSummary.css" rel="stylesheet" type="text/css"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div style="padding: 0 1em 1em 1em;">
<div class="searchBoxContainer">
    <asp:TextBox ID="txtSearch" CssClass="searchBox" runat="server" placeholder="Search by Name"></asp:TextBox>
    <asp:ImageButton ID="Button1" runat="server" AlternateText="Search" ImageUrl="~/Images/magnifying_glass_icon.png"/>
</div>
<div class="gridViewContainer">
    <asp:GridView ID="GridView1" CssClass="gridView" runat="server" AllowPaging="True"
                  AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ProductID"
                  DataSourceID="ProductSource" ForeColor="#333333" GridLines="None" OnRowDeleted="GridView1_RowDeleted"
                  OnRowUpdated="GridView1_RowUpdated">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775"/>
        <Columns>
            <asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="True" SortExpression="ProductID">
                <ItemStyle HorizontalAlign="Right"/>
            </asp:BoundField>
            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" MaxLength="50" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox1"
                                                ErrorMessage="Product name is required." Text="*" ForeColor="Red" Display="Dynamic"
                                                ValidationGroup="Edit">
                    </asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description" SortExpression="Description">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" MaxLength="250" TextMode="MultiLine" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
                                                ErrorMessage="Product description is required." Text="*" ForeColor="Red" Display="Dynamic"
                                                ValidationGroup="Edit">
                    </asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("Description").ToString().Replace(Environment.NewLine, "<br/>") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Group" SortExpression="Group">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" MaxLength="50" runat="server" Text='<%# Bind("Group") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3"
                                                ErrorMessage="Product group is required." Text="*" ForeColor="Red" Display="Dynamic"
                                                ValidationGroup="Edit">
                    </asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Group") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Unit Selling Price" SortExpression="UnitSellingPrice">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" Width="75" min="1" runat="server" TextMode="Number" Text='<%# Bind("UnitSellingPrice") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox4"
                                                ErrorMessage="Unit selling price is required." Text="*" ForeColor="Red" Display="Dynamic"
                                                ValidationGroup="Edit">
                    </asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Eval("UnitSellingPrice", "{0:c}") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Right"/>
            </asp:TemplateField>
            <asp:BoundField DataField="Stock" HeaderText="Stock" ReadOnly="True" SortExpression="Stock">
                <ItemStyle HorizontalAlign="Right"/>
            </asp:BoundField>
            <asp:TemplateField HeaderText="Action" ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" ValidationGroup="Edit" runat="server" CausesValidation="True"
                                    CommandName="Update" Text="Update">
                    </asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                          Text="Cancel">
                    </asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                    Text="Edit">
                    </asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                                          Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this product?');">
                    </asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataRowStyle CssClass="emptyDataRow"></EmptyDataRowStyle>
        <EmptyDataTemplate>
            <table class="gridView" id="ContentPlaceHolder1_GridView1" style="border-collapse: collapse; color: #333333; width: 40em;">
                <tr style="background-color: #5D7B9D; color: White; font-weight: bold;">
                    <th scope="col">
                        Product ID
                    </th>
                    <th scope="col">
                        Name
                    </th>
                    <th scope="col">
                        Description
                    </th>
                    <th scope="col">
                        Group
                    </th>
                    <th scope="col">
                        Unit Selling Price
                    </th>
                    <th scope="col">
                        Stock
                    </th>
                </tr>
                <tr style="background-color: #F7F6F3; color: #333333;">
                    <td colspan="6">
                        NO PRODUCT FOUND
                    </td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <EditRowStyle BackColor="#999999"/>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"/>
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"/>
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"/>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"/>
        <SortedAscendingCellStyle BackColor="#E9E7E2"/>
        <SortedAscendingHeaderStyle BackColor="#506C8C"/>
        <SortedDescendingCellStyle BackColor="#FFFDF8"/>
        <SortedDescendingHeaderStyle BackColor="#6F8DAE"/>
    </asp:GridView>
    <asp:ValidationSummary ID="ValidationSummary2" Style="margin-top: 1em;" CssClass="validationSummary"
                           HeaderText="<b>Please fix following error(s):</b>" ValidationGroup="Edit" ForeColor="Red"
                           runat="server"/>
</div>
<asp:EntityDataSource ID="ProductSource" runat="server" ConnectionString="name=XYZDBContext"
                      DefaultContainerName="XYZDBContext" EnableDelete="True" EnableFlattening="False"
                      EnableInsert="True" EnableUpdate="True" EntitySetName="FinishedProductInventories"
                      EntityTypeFilter="FinishedProductInventory" OrderBy="it.ProductID DESC" Where="it.Name LIKE '%'+@Name +'%' OR @Name is NULL">
    <WhereParameters>
        <asp:ControlParameter ControlID="txtSearch" DbType="String" Name="Name" PropertyName="Text"/>
    </WhereParameters>
</asp:EntityDataSource>
<br/>
<br/>
<asp:DetailsView ID="DetailsView1" style="float: left;" CssClass="detailsView" runat="server" AutoGenerateRows="False"
                 CellPadding="4" DataKeyNames="ProductID" DataSourceID="ProductSource" DefaultMode="Insert"
                 ForeColor="#333333" GridLines="None" Height="50px" Width="125px" OnItemInserted="DetailsView1_ItemInserted"
                 HeaderText="Register a product">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775"/>
    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True"/>
    <EditRowStyle BackColor="#999999"/>
    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True"/>
    <Fields>
        <asp:BoundField DataField="ProductID" HeaderText="Product ID" InsertVisible="False"
                        SortExpression="ProductID"/>
        <asp:TemplateField HeaderText="Name" SortExpression="Name">
            <InsertItemTemplate>
                <asp:TextBox ID="tbName" MaxLength="50" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                <asp:RequiredFieldValidator runat="server" ControlToValidate="tbName" ErrorMessage="Product name is required."
                                            Text="*" ForeColor="Red" Display="Dynamic" ValidationGroup="Insert">
                </asp:RequiredFieldValidator>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Description" SortExpression="Description">
            <InsertItemTemplate>
                <asp:TextBox ID="tbDescription" MaxLength="250" TextMode="MultiLine" runat="server"
                             Text='<%# Bind("Description") %>'>
                </asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbDescription"
                                            ErrorMessage="Product description is required." Text="*" ForeColor="Red" Display="Dynamic"
                                            ValidationGroup="Insert">
                </asp:RequiredFieldValidator>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Group" SortExpression="Group">
            <InsertItemTemplate>
                <asp:TextBox ID="tbGroup" MaxLength="50" runat="server" Text='<%# Bind("Group") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tbGroup"
                                            ErrorMessage="Product group is required." Text="*" ForeColor="Red" Display="Dynamic"
                                            ValidationGroup="Insert">
                </asp:RequiredFieldValidator>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Unit Selling Price" SortExpression="UnitSellingPrice">
            <InsertItemTemplate>
                <asp:TextBox ID="tbPrice" Width="75" min="1" runat="server" TextMode="Number" Text='<%# Bind("UnitSellingPrice") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbPrice"
                                            ErrorMessage="Unit selling price is required." Text="*" ForeColor="Red" Display="Dynamic"
                                            ValidationGroup="Insert">
                </asp:RequiredFieldValidator>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowInsertButton="True" ValidationGroup="Insert" InsertText="Register"
                          ShowCancelButton="False"/>
        <asp:TemplateField ShowHeader="False">
            <ItemStyle BackColor="#E2DED6"/>
            <InsertItemTemplate>
                <asp:ValidationSummary ID="ValidationSummary1" CssClass="validationSummary" HeaderText="<b>Please fix following error(s):</b>"
                                       ValidationGroup="Insert" ForeColor="Red" runat="server"/>
            </InsertItemTemplate>
        </asp:TemplateField>
    </Fields>
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"/>
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"/>
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"/>
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
</asp:DetailsView>

<table class="table" style="float: left; padding-left: 1em;">
    <tr>
        <th colspan="2">
            Add Finished Products
        </th>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label1" AssociatedControlID="ddlProduct" runat="server" Text="Product"></asp:Label>
        </td>
        <td style="text-align: left;">
            <asp:DropDownList ID="ddlProduct" runat="server" DataSourceID="ProductSource" DataTextField="Name"
                              DataValueField="ProductID">
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlProduct"
                                        ErrorMessage="Product is required." Text="*" ForeColor="Red" Display="Dynamic"
                                        ValidationGroup="Manufacture">
            </asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label2" runat="server" AssociatedControlID="txtProductQty" Text="Quantity"></asp:Label>
        </td>
        <td>
            <asp:TextBox ID="txtProductQty" Width="75" min="1" runat="server" TextMode="Number"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtProductQty"
                                        ErrorMessage="Product quantity is required." Text="*" ForeColor="Red" Display="Dynamic"
                                        ValidationGroup="Manufacture">
            </asp:RequiredFieldValidator>
            <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtProductQty"
                                 ErrorMessage="Some of the raw materials of this product is out of stock" Text="*"
                                 ForeColor="Red" Display="Dynamic" ValidationGroup="Manufacture">
            </asp:CustomValidator>
            <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="txtProductQty"
                                 ErrorMessage="There are no raw materials assigned for this product" Text="*"
                                 ForeColor="Red" Display="Dynamic" ValidationGroup="Manufacture">
            </asp:CustomValidator>
        </td>
    </tr>
    <tr>
        <td colspan="2" style="background-color: #E2DED6; color: #284775; font-weight: bold;">
            <asp:Button ID="btnAdd" runat="server" ValidationGroup="Manufacture" Text="ADD" OnClick="btnAdd_OnClick"/>
        </td>
    </tr>
    <tr>
        <td colspan="2" style="background-color: #E2DED6; color: #284775;">
            <asp:ValidationSummary ID="ValidationSummary1" CssClass="validationSummary" HeaderText="<b>Please fix following error(s):</b>"
                                   ValidationGroup="Manufacture" ForeColor="Red" runat="server"/>
        </td>
    </tr>
</table>
<br style="clear: both;"/><br/>
<fieldset style="padding: 0.5em; width: 35em;">
    <legend>Import data from CSV</legend>
    <asp:FileUpload ID="FileUpload1" accept=".csv" BackColor="#5D7B9D" ForeColor="white" style="-ms-border-radius: 0.5em; border-radius: 0.5em; outline: none; padding: 0.5em;" runat="server"/>
    <asp:Button ID="Button2" OnClick="Button2_OnClick" style="-ms-border-radius: 0.5em; border-radius: 0.5em; outline: none; padding: 0.5em;" runat="server" Text="Import"/>
    <asp:Label ID="lblImport" runat="server"></asp:Label>
</fieldset>
</div>
</asp:Content>